﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace nwrole.console
{
    public class ConsoleCommands : CommandBase
    {
        [Command("exit", "quit")]
        public void Exit ()
        {
            Environment.Exit(0);
        }

        [Command("set", "store")]
        [GenericCommand]
        public void SetVariable (Dictionary<string, object> dict)
        {
            foreach (var kvp in dict)
            {
                Variables[kvp.Key] = kvp.Value;
                this.PrintLine(ConsoleColor.DarkGreen, (kvp.Key + ":").PadRight(10) + Convert.ToString(kvp.Value));
            }
        }

        [Command("echo", "get")]
        public void GetVariable (string name)
        {
            object o = null;
            if (Variables.TryGetValue(name, out o))
                this.PrintLine((name + ":").PadRight(20) + Convert.ToString(o));
            else
                this.PrintLine(ConsoleColor.DarkRed, (name + ":").PadRight(10) + "variable not found");
        }

        [Command("list-variables")]
        public void ListVariables()
        {
            this.PrintObject(Variables);
        }

        [Command("pause")]
        public void Pause ()
        {
            this.PrintLine(ConsoleColor.Magenta, "Press any key to continue...");
            Console.ReadKey(false);
        }

        [Command("clear", "clr")]
        public void Clear ()
        {
            Console.Clear();
        }
    }
}
